package olympicgameslogic;

import java.io.Serializable;

/**
 *
 * @author Fábio
 */
public class Team implements Serializable, OurComparable {

   private Delegation delegation;
   private Modality modality;
   private LinkedList<Athlete> athletes = new LinkedList();

   public Team(Delegation delegation, Modality modality) {
      setDelegation(delegation);
      setModality(modality);

   }

   public Team(Delegation delegation, int num_elements, Modality modality, LinkedList<Athlete> athletes) {
      setDelegation(delegation);
      setAthletes(athletes);
      setModality(modality);
   }

   public Team(Delegation delegation) {
      setDelegation(delegation);

   }

   public Team() {
   }

   /**
    * @return the Delegation
    */
   public Delegation getDelegation() {
      return delegation;
   }

   /**
    * @return the modality
    */
   public Modality getModality() {
      return modality;
   }

   /**
    * @return the athletes
    */
   public LinkedList<Athlete> getAthletes() {
      return athletes;
   }

   /**
    * @param delegation the delegation to set
    */
   public void setDelegation(Delegation delegation) {
      this.delegation = delegation;
   }

   /**
    * @param discipline the discipline to set
    */
   public void setModality(Modality modality) {
      this.modality = modality;
   }

   /**
    * @param athletes the athletes to set
    */
   public void setAthletes(LinkedList<Athlete> athletes) {
      this.athletes = athletes;
   }

   public void addAthlete2Team(Athlete a) {
      athletes.add(a);
   }

   

   @Override
   public String toString() {
      return "\n" + athletes.getSize() + "\n" + athletes;
   }

   @Override
   public boolean isEqual(Object obj) {
      int matchCount = 0;

      if (athletes.size() != ((Team) obj).getAthletes().size()) {
	 return false;
      } else {
	 for (Athlete athlete : athletes) {
	    for (Athlete athlete1 : ((Team) obj).getAthletes()) {

	       if (athlete == athlete1) {
		  matchCount++;
	       }

	    }


	 }

	 if (matchCount == athletes.size()) {
	    return true;
	 }

      }
      return false;
   }
}
